<?php 
class Advertisment_model extends CI_Model{
	/*
	*  use for table advertisment 
	*/	
	// get all from brand
	function get_all_advertisment($limit = 0 , $start = 0){
		$q = $this->db->select()
					  ->from('advertisment')
					  ->order_by('adv_startdate','desc')
					  ->limit($limit, $start)
					  ->get();				  
		$res['rows'] = $q->result();
		// get all no limit
		$q1 = $this->db->select()
					  ->from('advertisment')
					  ->order_by('adv_startdate','desc')
					  ->get();
		$res['all'] = $q1->result();
		// count
        $res['totalRows'] = $this->db->count_all('advertisment');
		
		return $res;
	}
	// get advertisment by adv_id
	function get_advertisment_by_id($id=null){
		$q = $this->db->select()
					  ->from('advertisment')
					  ->where('adv_id',$id)
					  ->get();				  
		$res = $q->row();
		return json_encode($res);
	}
	
	
	// add new advertisment
	function add_advertisment($data){
			$this->db->insert('advertisment',$data);
			return;
	}
	// edit advertisment by id
	function edit_advertisment($id,$data){
			$this->db->where('adv_id',$id) ;
			$this->db->update('advertisment',$data);
			return;
	}
	//delete advertisment by id
	function delete_advertisment($id){
		foreach($id as $item){
			$this->db->where('adv_id',$item)
					 ->delete('advertisment');
		}
		return;
	}// ? delete in 
}